using System.Collections;
using UnityEngine;

public class PointsLabel : MonoBehaviour
{
	public UILabel label;

	public float duration = 1f;

	public float fadeInOut = 0.1f;

	public FloatRange alphaRange = default(FloatRange);

	private Vector3 worldPosition;

	private int points;

	public void SetPoints(int points, Vector3 worldPosition, Color color)
	{
		label.color = color;
		this.points = points;
		label.text = points.ToString();
		label.cachedGameObject.SetActive(true);
		this.worldPosition = worldPosition;
		SetWorldPosition(worldPosition);
		StopAllCoroutines();
		StartCoroutine(DoShowQuality());
	}

	public void SetWorldPosition(Vector3 worldPosition)
	{
		Vector3 position = UICamera.mainCamera.ScreenToWorldPoint(Camera.main.WorldToScreenPoint(worldPosition));
		position.z = label.cachedTransform.position.z;
		label.cachedTransform.position = position;
	}

	public void Hide()
	{
		label.text = string.Empty;
	}

	public IEnumerator DoShowQuality()
	{
		label.alpha = alphaRange.min;
		label.cachedTransform.localScale = new Vector3(1.5f, 1.5f, 1f);
		TweenScale.Begin(label.cachedGameObject, fadeInOut, Vector3.one);
		TweenAlpha.Begin(label.cachedGameObject, fadeInOut, alphaRange.max);
		float time = 0f;
		TweenScale.Begin(label.cachedGameObject, duration, Vector3.one * 0.5f);
		int countDuration = 0;
		while (time < (float)countDuration)
		{
			time += Time.deltaTime;
			label.text = Mathf.FloorToInt(Mathf.Lerp(0f, points, time / (float)countDuration)).ToString();
			yield return null;
		}
		label.text = points.ToString();
		yield return new WaitForSeconds(duration - (float)countDuration);
		TweenAlpha.Begin(label.cachedGameObject, fadeInOut, alphaRange.min);
		yield return new WaitForSeconds(fadeInOut);
		label.cachedGameObject.SetActive(false);
	}

	private void Update()
	{
		SetWorldPosition(worldPosition);
	}
}
